<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/

$_SESSION["sessdata"]["pagefrom"]=$_SERVER["QUERY_STRING"];

?>

<script language="javascript">

function jumpPage()
{
 	if (document.catform.viewcategory.selectedIndex > 0)
	{
      		top.location.href = (document.catform.viewcategory.options[document.catform.viewcategory.selectedIndex].value)
   	}
	else
	{
    		return true;
   	}
}

</script>


	<p>Current Global Settings:

	<?
	$parseini= new ParseIni("crontab");
	$globalSettings=$parseini->read_inifile();
	if ($globalSettings["global"]["globalstatus"]=="on")
	{
		echo "Normal, all functioning per individual settings";
	}
	if ($globalSettings["global"]["globalstatus"]=="off")
	{
		echo "Crons have been <b>disabled globally</b>";
	}
	if ($globalSettings["global"]["globalstatus"]=="delay" && $globalSettings["global"]["globaldelay"]>time())
	{
		echo "Crons are <b>globally delayed</b> until <b>".get_time_str($globalSettings["global"]["globaldelay"],2)."</b>";
	}
	if ($globalSettings["global"]["globalstatus"]=="disablemonitoring")
	{
		echo "Monitoring on Crons are <b>globally disabled</b>";
	}
	echo "</p>";

?>

<table border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td>

<?
if ($BigDaddy->IsUserAllowedByAction("cron-global"))
{
    ?>
	<ul>
		<li><b>Global</b></li>
		<li><a href="/crontab/query_crontab.php?action=resetnormal">Reset Global Status to Normal</a></li>
		<li><a href="/crontab/query_crontab.php?action=globaldisable">Disable Crons from running</a></li>
		<li><a href="<?=$_SERVER["PHP_SELF"];?>?page=CronDelayGlobal">Set Delay for all Enabled Crons</a></li>
		<li><a href="/crontab/query_crontab.php?action=globaldisablemonitoring">Disable Monitoring Only For All Crons</a></li>
	</ul>
    <?
}
?>
</td>
<td width="10">&nbsp;</td>
<td>

<?

if ($_REQUEST["catID"]>0 && $_REQUEST["show_only"]=="" && !$bNoShowCategory)
{
	$catInfo = $BigDaddyData->GetCronCategoryInfoByID($_REQUEST["catID"]);
	
	?>

	<ul>
		<li><b>By Category: <?=$catInfo["name"];?></b></li>
        <?
        if ($BigDaddy->IsUserAllowedByAction("cron-enable"))
        {
            ?>
            <li><a href="/crontab/query_crontab.php?action=enableall&catID=<?=$_REQUEST["catID"];?>" onclick="javascript: return confirm ('Enable All Crons in <?=$catInfo["name"];?>?');">Enable All Crons In Category</a></li>
            <?
        }
        
        if ($BigDaddy->IsUserAllowedByAction("cron-disable"))
        {
            ?>
            <li><a href="/crontab/query_crontab.php?action=disableall&catID=<?=$_REQUEST["catID"];?>" onclick="javascript: return confirm ('Disable All Crons in <?=$catInfo["name"];?>?');">Disable All Crons In Category</a></li>
            <?
        }
        
        if ($BigDaddy->IsUserAllowedByAction("cron-delay"))
        {
            ?>
            <li><a href="<?=$_SERVER["PHP_SELF"];?>?page=CronDelayAll&catID=<?=$_REQUEST["catID"];?>">Delay All Crons in Category</a><br /><br /></li>
            <?
        }
        
        if ($BigDaddy->IsUserAllowedByAction("cron-mon-enable"))
        {
            ?>
            <li><a href="/crontab/query_crontab.php?action=disablemonall&catID=<?=$_REQUEST["catID"];?>" onclick="javascript: return confirm ('Disable Monitoring On All Crons in <?=$catInfo["name"];?>?');">Disable Monitoring On All Crons In Category</a></li>
            <?
        }
        
        if ($BigDaddy->IsUserAllowedByAction("cron-mon-disable"))
        {
            ?>
            <li><a href="/crontab/query_crontab.php?action=enablemonall&catID=<?=$_REQUEST["catID"];?>" onclick="javascript: return confirm ('Enable Monitoring On All Crons in <?=$catInfo["name"];?>?');">Enable Monitoring On All Crons In Category</a></li>
            <?
        }
        ?>
	</ul>


	<?

}
?>

</td>
</tr>
</table>


<?
if ($catInfo["name"]!="")
{
?>
<p><b>Viewing Category: <?=$catInfo["name"];?></b></p>
<?
}
?>



<form name="catform" >
<div class="orgbar" align="center">

<span class="text">

<?

$pn=$_REQUEST["pn"];

if ($pn==0 || !isset($pn) || $pn=="") {
        $pn=1;
}

$max_num=14; //Max Number to show on a page

$nStart = ($pn-1) * $max_num;

if ($_REQUEST["show_only"]=="disabled")
{
	
	$aCriteria = array(
		"active" => 0,
		"start_number" => $nStart,
		"max_results" => $max_num
		);
	
}
else if ($_REQUEST["show_only"]=="enabled")
{
	$aCriteria = array(
		"active" => 1,
		"start_number" => $nStart,
		"max_results" => $max_num
		);
}
else if ($_REQUEST["show_only"]=="delayed")
{
	$aCriteria = array(
		"active" => 2,
		"start_number" => $nStart,
		"max_results" => $max_num
		);
}
else if ($_REQUEST["catID"]>0)
{
	$aCriteria = array(
		"catID" => $_REQUEST["catID"],
		"start_number" => $nStart,
		"max_results" => $max_num
		);
		
}
else if ($_REQUEST["show_only"]=="running")
{
	$aCriteria = array(
		"active" => 1,
		"start_number" => $nStart,
		"max_results" => $max_num,
		"running" => true
		);
}
else
{
	$aCriteria = array(
		"active" => -1,
		"start_number" => $nStart,
		"max_results" => $max_num
		);
}

$aCrons = $BigDaddyData->GetCrons($aCriteria);
if (is_array($aCrons["aResults"]))
{
	$num_pages=ceil( $aCrons["nTotalRows"] /$max_num );
}

//Start Number
$pstr="<b>Pages:</b> ";

for ($p=1;$p<=$num_pages;$p++)
{
        if ($p==$pn)
		{
                $pstr.="<b>".$p."</b> ";
        }
		else
		{
                $pstr.="<a href=\"index.html?page=CrontabIndex&catID=".$_REQUEST["catID"]."&pn=".$p."&show_only=".$_REQUEST["show_only"]."\">".$p."</a> ";
        }
}

?>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?=$pstr;?>
</span>
</div>

<table border="0" cellpadding="0" cellspacing="0" width="97%">

<?

if (!is_array($aCrons["aResults"]))
{
?>
	<tr valign="middle">
	<td class="lineitem">
	<div align="center"><b>No crons match your criteria</b></div>
	</td>
	</tr>
<?
}
else
{
	foreach ($aCrons["aResults"] as $nIndex => $row)
	{
		$BigDaddyDisplay->ShowCronLine($row);
	}
}
?>

</table>
</form>
</div>
